<template>
  <f7-page>
    <f7-navbar title="修改密码" back-link="Back"></f7-navbar>
    <f7-list inline-labels no-hairlines-md>
      <f7-list-input
        label="旧密码"
        type="password"
        :value="password1"
        @input="password1 = $event.target.value"
        clear-button
      ></f7-list-input>
      <f7-list-input
        label="新密码"
        type="password"
        clear-button
        :value="password2"
        @input="password2 = $event.target.value"
      ></f7-list-input>
      <f7-list-input
        label="确认密码"
        type="password"
        clear-button
        :value="password3"
        @input="password3 = $event.target.value"
      ></f7-list-input>
    </f7-list>
    <f7-block>
      <f7-button fill @click="queren">确认修改</f7-button>
    </f7-block>
  </f7-page>
</template>
<script>
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      password1: "",
      password2: "",
      password3: ""
    };
  },
  methods: {
    queren() {
      const self = this;
      const app = self.$f7;
      if (this.password2 === this.password3) {
        URL = "/caofuying/user/updataUser";
        axios
          .post(
            URL,
            qs.stringify({
              Username: this.$store.state.apiLogin.Username,
              Password: this.password1,
              newPassword: this.password2
            })
          )
          .then(r => {
            const { data } = r;
            if (data === 1) {
              app.dialog.alert("修改成功");
            } else if (data === 3) {
              app.dialog.alert("旧密码错误");
            } else {
              app.dialog.alert("服务器错误");
            }
          });
      } else {
        app.dialog.alert("您输入的新密码和确认密码不一致");
      }
    }
  }
};
</script>
<style scoped>
</style>
